package vue;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import modele.Match;

@SuppressWarnings("serial")
public class PopupInfoMatch extends JFrame {
	

	
	public PopupInfoMatch(Match match) {

		setTitle("Info match");
		setLocation(100, 100);
		setSize(750, 200);
		
		JPanel panelGeneral = new JPanel(new GridLayout(1,3));
		/*Panel EQUIPE1*/
		JPanel panel = new JPanel(new GridLayout(5,1));
		panel.setBorder(BorderFactory.createEmptyBorder(60, 60, 10, 10));
		panel.setBorder(BorderFactory.createLineBorder(Color.black));
		panel.setBackground(Color.white);
		panel.add(new JLabel(match.getEquipe1().getNom()));
		ArrayList<Match> alMatchEquipe1 = match.getEquipe1().getListeMatch();
		
		JLabel der = new JLabel("Dernier match:");
		der.setForeground(Color.RED);
		panel.add(der);
		
		int scoreEquipe1=-1;
		for(int i =0 ;scoreEquipe1<0 && i<alMatchEquipe1.size()-1;i++) {
			if(alMatchEquipe1.get(i).getScoreEquipe2() <0 )
				scoreEquipe1 = -1;
			else
			{
				scoreEquipe1 = 1;	
				panel.add(new JLabel(alMatchEquipe1.get(i).toString()));
			}
		}
		if(scoreEquipe1 == -1) {
			panel.add(new JLabel("Aucun match"));
		}
		
		JLabel serie = new JLabel("Série en cours");
		serie.setForeground(Color.RED);
		panel.add(serie);
		
		if(alMatchEquipe1.size()-2 >=0)
			panel.add(new JLabel(match.getEquipe1().getSerie()));
		else
			panel.add(new JLabel("Aucune"));
		
		panelGeneral.add(panel);
		
		/*PANEL INFO*/
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd" );
		JPanel panelInfo = new JPanel();
		panelInfo.add(new JLabel("<html>Date: "+f.format(match.getDate())+"<br> Lieu: "+match.getLieu()+"</html>"),BorderLayout.CENTER);
		panelGeneral.add(panelInfo);
		
		/*PANEL EQUIPE2*/
		JPanel panel2 = new JPanel(new GridLayout(5,1));
		panel2.setBorder(BorderFactory.createEmptyBorder(60, 70, 10, 10));
		panel2.setBorder(BorderFactory.createLineBorder(Color.black));
		panel2.add(new JLabel(match.getEquipe2().getNom()));
		ArrayList<Match> alMatchEquipe2 = match.getEquipe2().getListeMatch();
		
		JLabel der2 = new JLabel("Dernier match:");
		der2.setForeground(Color.RED);
		panel2.add(der2);
		
		int scoreEquipe2=-1;
		for(int i =0 ;scoreEquipe2<0 && i<alMatchEquipe2.size()-1;i++) {
			if(alMatchEquipe2.get(i).getScoreEquipe2() <0 )
				scoreEquipe2 = -1;
			else
			{
				scoreEquipe2 = 1;	
				panel2.add(new JLabel(alMatchEquipe2.get(i).toString()));
			}
		}
		if(scoreEquipe2 == -1) {
			panel2.add(new JLabel("Aucun match"));
		}
		
		JLabel serie2 = new JLabel("Série en cours");
		serie2.setForeground(Color.RED);
		panel2.add(serie2);
		
		System.out.println("nbMatch:" +alMatchEquipe2.size() );
		if(alMatchEquipe2.size()-2 >=0)
			panel2.add(new JLabel(match.getEquipe2().getSerie()));
		else
			panel2.add(new JLabel("Aucune"));
		
		panelGeneral.add(panel2);
		
		this.add(panelGeneral);

		setVisible(true);
	}
	
}
